<template>
  <div class="app-container">

    <el-dialog :title="title" center :visible.sync="addUpdateOpen" width="800px" :close-on-click-modal="false">
      <el-form ref="form" :model="form" label-width="90px" class="showContent">
        <el-form-item label="帮助标题：" prop="infoTitle">
          <span v-html="form.infoTitle"></span>
        </el-form-item>

        <el-form-item label="所属分类：" prop="categoryName">
          <span v-html="form.categoryName"></span>
        </el-form-item>

        <el-form-item label="帮助简介：" prop="introduction">
          <span v-html="form.introduction"></span>
        </el-form-item>


        <el-form-item label="创建时间：" prop="createTime">
          <span v-html="form.createTime"></span>
        </el-form-item>

        <el-form-item label="更新时间：" prop="updateTime">
          <span v-html="form.updateTime"></span>
        </el-form-item>

        <el-form-item label="创建部门：" prop="createDeptName">
          <span v-html="form.createDeptName"></span>
        </el-form-item>

        <el-form-item label="创建用户：" prop="createUserName">
          <span v-html="form.createUserName"></span>
        </el-form-item>

        <el-form-item label="帮助内容：" prop="infoContent">
          <span v-html="form.infoContent"></span>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancelAddUpdateOpen">关 闭</el-button>
      </div>
    </el-dialog>


    <el-row :gutter="20">
      <el-col>
        <el-form :model="queryParams" ref="queryForm" :inline="true"  v-show="showSearch" label-width="80px">
          <el-form-item label="帮助标题" prop="infoTitle">
            <el-input v-model="queryParams.infoTitle" placeholder="请输入帮助标题" size="small" clearable style="width: 150px"/>
          </el-form-item>

          <el-form-item label="所属分类" prop="categoryName">
            <el-input v-model="queryParams.categoryName" placeholder="请输入所属分类" size="small" clearable style="width: 150px"/>
          </el-form-item>

          <el-form-item label="创建部门" prop="createDeptName">
            <el-input v-model="queryParams.createDeptName" placeholder="请输入创建部门" size="small" clearable style="width: 150px"/>
          </el-form-item>

          <el-form-item label="更新时间">
            <el-date-picker @change="handleQuery" v-model="dateRange" size="small" style="width: 240px" value-format="yyyy-MM-dd" type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"/>
          </el-form-item>
          <el-form-item>
            <el-button type="primary"  size="mini" icon="el-icon-search" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery('queryForm')">重置</el-button>
          </el-form-item>
        </el-form>
        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button type="primary"  icon="el-icon-view" size="mini" :disabled="single" @click="handleHelpInfoRead">阅读</el-button>
          </el-col>
          <right-toolbar :showSearch.sync="showSearch" @queryTable="queryHelpInfoPageResList" :columns="columns"></right-toolbar>
        </el-row>
        <el-table ref="multipleTable" :stripe="true" v-loading="loading" :data="dataList" @selection-change="handleSelectionChange"
                    @sort-change='tableSortChange' :default-sort="{prop: 'sort', order: 'descending'}">
          <el-table-column type="selection" align="center"/>
          <el-table-column label="帮助标题" align="left" prop="infoTitle"/>
          <el-table-column label="所属分类" align="left" prop="categoryName" width="150"/>
          <el-table-column label="创建部门" align="left" prop="createDeptName"  width="150" :show-overflow-tooltip="true"/>
          <el-table-column label="创建时间" align="center" prop="createTime" sortable='custom' width="200" />
          <el-table-column label="更新时间" align="center" prop="updateTime" sortable='custom' width="200" />
          <el-table-column label="操作" align="center" width="150" class-name="small-padding fixed-width">
            <template slot-scope="scope">
              <el-button size="mini" type="text" icon="el-icon-view"  @click="handleHelpInfoRead(scope.row)">阅读</el-button>
            </template>
          </el-table-column>
        </el-table>
        <pagination v-show="total>0"  :total="total" :page.sync="queryParams.page" :limit.sync="queryParams.rows" @pagination="queryHelpInfoPageResList"/>
      </el-col>
    </el-row>
  </div>
</template>

<script>
  import {queryHelpInfoPageResList,queryHelpInfoResByInfoId} from '@/api/help/helpInfo'
  //默认查询参数
  let defaultQueryParams = {
    infoContent: undefined,
    introduction: undefined,
    infoTitle: undefined,
    categoryId: undefined,
    createDeptName: undefined,
    createUserName: undefined,
    categoryName: undefined,
    page: 1,
    rows: 10
  }
  export default {
    name: 'helpInfoAdmin',
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 总条数
        total: 0,
        // 增加修改表单参数
        form: {},
        // 弹出层标题
        title: "",
        // 是否显示新增修改弹出层
        addUpdateOpen: false,
        // 显示搜索条件
        showSearch: true,
        //操作帮助信息发布
        dataList: [],
        // 日期范围
        dateRange: [],
        // 查询参数
        queryParams: { ...defaultQueryParams },
        //列帮助信息
        columns: [],
      }
    },
    created() {
      //查询帮助信息发布列表
      this.queryHelpInfoPageResList()
    },
    methods: {
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.infoId)
        this.single = selection.length !== 1;
        this.multiple = !selection.length
      },
      //排序
      tableSortChange(column) {
        //格式化排序参数，构建中
        this.orderByFormat(this.queryParams,column);
        //执行查询方法
        this.queryHelpInfoPageResList()
      },

      /** 查询帮助信息发布列表 */
      queryHelpInfoPageResList() {
        this.loading = true
        queryHelpInfoPageResList(this.addDateRange(this.queryParams, this.dateRange)).then(res => {
            this.dataList = res.data.records
            this.total = res.data.total
          }
        ).finally(() => {
          //关闭加载特效
          this.loading = false
        })
      },

      //查看详情
      handleHelpInfoRead(row){
        row = row.isTrusted ? this.$refs.multipleTable.selection[0] : row;
        this.addUpdateOpen = true;
        this.title = "阅读详情";
        queryHelpInfoResByInfoId({ infoId: row.infoId }).then(res => {
          this.form = res.data;
        });
      },
      // 取消修改增加弹出层按钮
      cancelAddUpdateOpen() {
        this.addUpdateOpen = false
      },

      /** 重置按钮操作 */
      resetQuery(fromId) {
        this.dateRange = []
        this.resetForm(fromId)
        this.handleQuery()
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.page = 1
        this.queryHelpInfoPageResList()
      }
    }
  }
</script>
<style lang="scss" scoped>
  .showContent {
    // 必须有高度 overflow 为自动
    overflow: auto;
    height: 600px;
    border-top: 1px solid #eff1f4;
    border-bottom: 1px solid #eff1f4;
    // 滚动条的样式,宽高分别对应横竖滚动条的尺寸
    &::-webkit-scrollbar {
      width: 3px;
    }

    // 滚动条里面默认的小方块,自定义样式
    &::-webkit-scrollbar-thumb {
      background: #8798AF;
      border-radius: 2px;
    }

    // 滚动条里面的轨道
    &::-webkit-scrollbar-track {
      background: transparent;
    }

    .el-form-item{
      margin-bottom:10px;
    }
  }
</style>
